package models

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"token-for-token/global"
)

type ChainToken struct {
	Id            primitive.ObjectID `bson:"_id ,omitempty"`
	ChainName     string             `bson:"chainName"`
	ChainId       int64              `bson:"chainId"`
	Address       string             `bson:"address"`
	Name          string             `bson:"name"`
	Symbol        string             `bson:"symbol"`
	Decimals      int32              `bson:"decimals"`
	ChainConfigId string             `bson:"chainConfigId"`
}

// 根据Address判断是否存在
func (c *ChainToken) GetChainTokenInfoForId(id string) error {
	user := global.DBEngine.Database(global.DbConfig.DbName).Collection("chain_token")
	// 将字符串ID转换为ObjectID
	objID, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return err
	}
	filter := bson.M{"_id": objID}
	err = user.FindOne(context.Background(), filter).Decode(&c)
	return err
}
